package com.medvalley.tcm.controller;

import com.medvalley.tcm.base.Result;
import com.medvalley.tcm.service.SMSService;
import com.medvalley.tcm.service.impl.ReportServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/web")
@Api(value = "web获取报告登录接口")
public class WebReportController extends BaseController {

    @Autowired
    private SMSService smsService;

    @Autowired
    private ReportServiceImpl reportService;

    @ApiOperation(value = "发送短信验证码")
    @RequestMapping(value = "/user/login", method = RequestMethod.POST)
    public Result login(@RequestParam("phone") String phone, @RequestParam("barCode") String barCode,
                        @RequestParam("smsCode") String smsCode) {
        if (StringUtils.isEmpty(phone)) {
            return error("手机号不能为空");
        }
        if (StringUtils.isEmpty(barCode)) {
            return error("提取码错误");
        }
        boolean result = smsService.validateCode(phone, smsCode);
        if (!result) {
            return error("验证码错误");
        }
        Map<String, Object> returnMap = reportService.webGetReportId(phone, barCode);
        return success(returnMap);
    }

}
